package HomeWork;
/*  5.将一个字符串进行反转，可以指定部分反转
   abcdefg--->abfedcg*/
public class work05 {
    public static void main(String[] args) {
        System.out.println("交换前:");
        String str="abcdefg";
        System.out.println(str);
        System.out.println("交换后:");
        str=reverse(str,2,5);
        System.out.println(str);
    }

    private static String reverse(String str, int start, int end) {
        char[] chars=str.toCharArray();
        char temp;
        for(int i=start,j=end;i<j;i++,j--){
            temp=chars[i];
            chars[i]=chars[j];
            chars[j]=temp;
        }
        return new String(chars);
    }
}
